<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/common.jspf" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>

</head>
<script type="application/javascript">

    $(document).ready(function(){

        var win = parent.$("iframe[title='退单管理']").get(0).contentWindow;
        var row = win.$("#dg").datagrid("getSelected");
        //初始化页面信息
        $("#deskid").val(row.deskId);
        $("#deskname").val(row.deskName);
        $("#ordernum").val(row.orderNum);
        $("#refundsnum").val(row.refundsNum);
        $("#pay").val(row.refundsPay);
        $("#refundstime").val(row.refundsTime);
        $("#refundsstate").val(row.refundsState);
        $("#refundsreason").val(row.refundsReason);
        $("#payform").val(row.payForm);
        var danzong=0;//退款总额

        $('#bb').datagrid({
            url:"${proPath}/order/show.action",
            queryParams: {
                simpleOrder: row.orderNum,
                goodExitNum:1
            },

            columns:[[
                {checkbox: true},
                {field:'orderNum',title:'订单号',width:100},
                {field:'goodName',title:'商品名字',width:100},
                {field:'goodNum',title:'商品数量',width:100},
                {field:'goodPrice',title:'总价格',width:100},
                {field:'orderState',title:'菜品状态',width:100,formatter:rowformater},
                {field:'payForm',title:'付款形式',width:100},
                {field:'orderMessage',title:'备注',width:100,align:'right'}
            ]],
            toolbar: [{
                iconCls: 'icon-save',
                text:'单个通过',
                handler: function(){
                    var win = parent.$("iframe[title='退单管理']").get(0).contentWindow;
                    var row = win.$("#dg").datagrid("getSelected");
                    var deskid=row.deskId;//桌子ID
                    var deskname=row.deskName;//桌子名字
                    var refundsnum=row.refundsNum;//退单号码
                    var row1 = $("#bb").datagrid("getSelected");
                    var goodname=row1.goodName//获取退菜名字
                    var price=row1.goodPrice;//获取退菜价格
                    var total;//获取订单总价
                    if(row1==""||row1==null){
                        allow("请选择")
                    }else {
                        //生成退单明细
                        $.post(
                            "${proPath}/refunds/refundsMinginsert.action",
                            {   deskId:deskid,
                                deskName:deskname,
                                goodName:goodname,
                                goodPrice:price,
                                refundsNum:refundsnum,
                                payFrom:row.payForm,
                                statusAudits:8,

                            },
                            function (data) {
                                alert("订单生成");
                                danzong+=parseInt(price);
                                alert(danzong);
                                //修改订单状态
                               // parent.$('#win').window('close');
                                var win = parent.$("iframe[title='订单管理']").get(0).contentWindow;
                                win.$("#dg").datagrid("reload");
                            },
                            "json"
                        )
                        //修改订单明细真实数量为0
                        $.post(
                            "${proPath}/order/dantui.action",
                            {   orderNum:row1.orderNum,
                                goodExitNum:0

                            },
                            function (data) {
                                alert("订单明细真实数量修改为0")
                                //修改订单状态
                              $("#bb").datagrid("reload");


                            },
                            "json"
                        )
                    }
                }
            }, '-',{  iconCls: 'icon-save',
                text:'完成',
                handler: function(){
                    //修改订单退款额
                    $.post(
                        "${proPath}/refunds/tuizong.action",
                        {   refundsNum:row.refundsNum,
                            refundsPay:danzong,
                            statusAudits:6,
                        },
                        function (data) {
                            alert("退单金额已经修改完毕")
                            //修改订单应该付款 row.refundsPay parent.$(
                            var truepay=parseInt(row.refundsPay);
                                    truepay-=danzong;
                            $.post(
                                "${proPath}/order/shen.action",
                                {   orderNum:row.orderNum,
                                    orderTruepay:truepay

                                },
                                function (data) {
                                    alert("修改实际付款")
                                    //修改订单状态
                                    $("#bb").datagrid("reload");


                                },
                                "json"
                            )


                            $("#bb").datagrid("reload");
                            parent.$('#win').window('close');
                            win.$("#dg").datagrid("reload");
                        },
                        "json"
                    )
                }
             },],
            striped:true,
            rownumbers:true,
            pagination:true,
            pageSize:5,
            pageList:[1,2,3,4,5]
        });

    });

    function rowformater(value, row, index) {
        // alert(value);
        if (value==1){
            value="未付款"
        }else if (value==2){
            value="已付款"
        }
        return value

    }

    function fan() {
        //关闭窗口
        parent.$('#win').window('close');
    };

    function allow() {
        var mess=$("#message").val();
        if (mess==null||mess==''){
            alert("请填写信息")
        }else {
            var win = parent.$("iframe[title='退单管理']").get(0).contentWindow;
            var row = win.$("#dg").datagrid("getSelected");
            var refundsNum = row.refundsNum;
            alert(row.refundsNum);

            //修改订单状态
            $.post(
                "${proPath}/refunds/allow.action",
                {   refundsNum:row.refundsNum,
                    refundsReason:mess,
                    statusAudits:6,
                },
                function (data) {
                    alert("操作成功")


                    parent.$('#win').window('close');
                    win.$("#dg").datagrid("reload");
                },
                "json"
            );
            $.post(
                "${proPath}/order/shen.action",
                {  orderNum:row.orderNum, orderState:6,orderTruepay:0},
                function (data) {
                    alert("操作成功")
                    //修改订单状态
                    parent.$('#win').window('close');
                    win.$("#dg").datagrid("reload");
                },
                "json"
            );
        };
    }

    function bo() {
        var mess=$("#message").val();
        if (mess==null||mess==''){
            alert("请填写信息")
        }else {
            //获取父页面相关信息 获取订单号
            var win = parent.$("iframe[title='退单管理']").get(0).contentWindow;
            var row = win.$("#dg").datagrid("getSelected");
            var refundsNum = row.refundsNum;
            alert(row.refundsNum);

            $.post(
                "${proPath}/refunds/bohui.action",
                {  refundsNum:row.refundsNum,
                    refundsReason:mess,
                    statusAudits:7,},
                function (data) {
                    alert("操作成功")
                    //修改订单状态
                    parent.$('#win').window('close');
                    win.$("#dg").datagrid("reload");
                },
                "json"
            )
            $.post(
                "${proPath}/order/shen.action",
                {  orderNum:row.orderNum, orderState:7,orderTruepay:row.refundsPay},
                function (data) {
                    alert("操作成功")
                    //修改订单状态
                    parent.$('#win').window('close');
                    win.$("#dg").datagrid("reload");
                },
                "json"
            )
        };
    }



</script>

<body>



餐桌号:<input id="deskid" type="text" value="" class="easyui-validatebox">

餐桌名字:<input id="deskname" type="text" value="" class="easyui-validatebox">

订单号:<input id="ordernum" type="text" value="" class="easyui-validatebox"><br>

退单号:<input id="refundsnum" type="text" value="" class="easyui-validatebox">

退款金额:<input id="pay" type="text" value="" class="easyui-validatebox">

退单时间:<input id="refundstime" type="text" value="" class="easyui-validatebox"><br>

退款状态:<input id="refundsstate" type="text" value="" class="easyui-validatebox">

退款原因:<input id="refundsreason" type="text" value="" class="easyui-validatebox">

付款方式：<input id="payform" type="text" value="" class="easyui-validatebox">

审批说明：<input id="message" type="text" class="easyui-validatebox">



<div class="easyui-panel" title="结算页面">
    <table id="bb"></table>
    <a   class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="allow()">整桌通过</a><br>
    <a  href="" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="bo()">整桌驳回</a>
    <a   class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="fan()">返回</a><br>
</div>


</body>
<script>


</script>
</html>
